const install = (Vue) => {
  const getUni = () => {
    return new Promise((resolve) => {
      if (Vue.prototype.$uni) {
        resolve(Vue.prototype.$uni)
        return
      }
      // eslint-disable-next-line
      let _uni = uni || { env: {} }
      _uni.ready = false
      if ('onUniAppJSBridgeReady' in document) {
        document.addEventListener('UniAppJSBridgeReady', () => {
          _uni.ready = true
          _uni?.getEnv?.((res) => {
            _uni.env = res
          });
          Vue.prototype.$uni = _uni
          resolve(_uni)
        })
        return
      }
      _uni.ready = true
      _uni?.getEnv?.((res) => {
        _uni.env = res
      });
      Vue.prototype.$uni = _uni
      resolve(_uni)
    })
  }
  getUni()
  Vue.prototype.$getUni = getUni
}

export default {
  install
}